package com.hsj.goldstore.base;

import com.hsj.goldstore.utils.SignUtil;
import com.hsj.goldstore.utils.retrofit.ApiStore;
import com.hsj.goldstore.utils.retrofit.AppClient;

import org.reactivestreams.Subscriber;

import java.io.UnsupportedEncodingException;
import java.util.Map;

import io.reactivex.CompletableEmitter;
import io.reactivex.CompletableOnSubscribe;
import io.reactivex.Flowable;
import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.Scheduler;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import io.reactivex.internal.subscriptions.ArrayCompositeSubscription;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by Administrator on 2018/3/22.
 */

public class BaseModel {

    public ApiStore apiStore = AppClient.retrofit().create(ApiStore.class);

    
    public void addSubscribe(Observable observable, Observer observer) {

        observable
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /**
     * @param map
     * @return 签名设置
     */
  public   Map<String, Object>  sign(Map<String, Object> map) {
      map.put("timestamp", System.currentTimeMillis() / 1000);
        try {
            String sign =  SignUtil.createSign(map, true);
            map.put("sign", sign);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

        return map;
    }
}
